/*
 * @Author: 詹真琦(legendryztachi@gmail.com)
 * @Date: 2021-11-05 15:37:09
 * @LastEditors: 詹真琦(legendryztachi@gmail.com)
 * @LastEditTime: 2022-04-14 16:54:15
 * @FilePath: \code\cwp-front\pc-collaboration\src\handles\common\print\fragment\opinion.f.js
 * @Description: 意见。入参第一个统一为baseInfo的store
 */
import { createOptionList } from '../helper';
import api from '@/api';
export default (useBaseInfo, option) => {
  let optionObject = useBaseInfo.print.commentData; //这里有点不一样，这是一个对象
    // 参数组装
    let getCommentParams = () => {
      if (useBaseInfo) {
        if (useBaseInfo.print.commentDataParams) {
          return { ...useBaseInfo.print.commentDataParams, page: 1 };
        }
        var zwIframe = useBaseInfo.baseInfo.zwIframe.mainbody;
        var affair = useBaseInfo.baseInfo.businessData.affair;
        return {
          moduleId: zwIframe.moduleId,
          affairId: affair.id,
          moduleType: zwIframe.moduleType,
          offset: 1,
          limit: 10000, // 10000条意见数据属于是比较极端的情况，实际业务一般不会有这么多条意见数据
          queryType: 0
        };
      }
      return {};
    };
    api.commentGetList(getCommentParams()).then((res) => {
      let { commentData } = res;

      if (commentData) {
        optionObject = commentData[0] || {
          comments: [],
          commentTotal: 0,
          praiseTotal: 0,
          relatedToMe: 0
        };
        if (!optionObject.relatedToMe) {
          optionObject.relatedToMe = 0;
        }
        optionObject.relatedToMe = 0;
        const printCommentFragment = new PrintFragment(
          $.i18n('collaboration.colPrint.handleOpinion'), // 国际化，标题
          createOptionList(optionObject)
        );
        // 这里特殊处理， _doPrint方法里面会调用
        printCommentFragment.isCommentFrame = true;
        // 重新请求数据
        option.callback(printCommentFragment);
      } else {
        option.callback(null);
      }
    });
};
